package com.lanxiao.cloud.modules.oauth.controller.dubbo;

import com.lanxiao.cloud.common.core.exception.BusinessException;
import com.lanxiao.cloud.modules.oauth.application.OauthQueryManager;
import com.lanxiao.cloud.modules.oauth.application.PermissionCmdManager;
import com.lanxiao.cloud.modules.oauth.application.PermissionQueryManager;
import com.lanxiao.cloud.oauth.api.OauthDubboApi;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * @author ：qiaoliang
 * @date ：2021-09-10
 */
@DubboService
public class OauthDubboController implements OauthDubboApi {

  private final PermissionCmdManager permissionCmdManager;
  private final OauthQueryManager oauthQueryManager;

  public OauthDubboController(
      PermissionCmdManager permissionCmdManager,
      OauthQueryManager oauthQueryManager) {
    this.permissionCmdManager = permissionCmdManager;
    this.oauthQueryManager = oauthQueryManager;
  }

  /**
   *  解析token获取用户ID
   *
   * @author ：qiaoliang
   * @param token : token
   * @return java.lang.Long
   * @date 2021-09-14 14:30
   */
  @Override
  public Long checkToken(String token) {
    return oauthQueryManager.checkToken(token);
  }

  /**
   * 校验用户是否有权访问
   *
   * @author ：qiaoliang
   * @param userId : 用户ID
   * @param url : 请求url
   * @param method : 请求方式
   * @date 2021-09-10 11:17
   */
  @Override
  public void  checkUserPermission(Long userId, String url, String method) {
    permissionCmdManager.checkUserPermission(userId, url, method);
  }

}
